/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package za.co.pas.spaceandtime.model.ext;

import java.util.List;
import java.util.Vector;
import org.apache.log4j.Logger;
import za.co.pas.business.abstracts.AbstractDataModel;
import za.co.pas.business.data.Company;
import za.co.pas.spaceandtime.data.BedType;
import za.co.pas.spaceandtime.data.Building;
import za.co.pas.spaceandtime.data.RoomType;
import za.co.pas.spaceandtime.message.BuildingDetailChanged;
import za.co.pas.spaceandtime.message.RequestBuildingDetailChanged;
import za.co.pas.spaceandtime.message.RequestBuildingListChanged;
import za.co.pas.spaceandtime.model.BuildingDataModel;

/**
 *
 * @author alabuschagne
 */
public class BuildingDetailModel extends AbstractDataModel
{
    private List<Building> currentBuildings;
    private Building currentBuilding;
    private BuildingDataModel buildingDataModel;
    private static Logger logger = Logger.getLogger(BuildingDetailModel.class);

    private BuildingDetailModel()
    {
    }

    public BuildingDetailModel(BuildingDataModel buildingDataModel)
    {
        super();
        this.buildingDataModel = buildingDataModel;
    }

    private void fireBuildingChanged()
    {
        firePropertyChange(new BuildingDetailChanged(currentBuilding));
    }

    public void setCurrentBuildingList(List<Building> b)
    {
        currentBuildings = b;
    }

     public void setCurrentBuildingList(Vector b)
    {
        currentBuildings = (List<Building>)b;
    }

    public void setRequestCurrentBuilding(Building b)
    {
        firePropertyChange(new RequestBuildingDetailChanged(currentBuilding, b));
    }

    public List<Building> getBuildings(Company c, Boolean force)
    {
        return buildingDataModel.getBuildings(c, force);
    }

    /**
     * This gets the building list, it is a set function because of the mvc reflection.
     * Call the RequestBuildingList first, this allows the view to check for changes.
     * @param c
     * @param force
     * @return
     */
    /*public void setBuildingList(Company c, Boolean force)
    {
        firePropertyChange(new BuildingListChanged(buildingDataModel.getBuildings(c, force)));
    }*/

    /**
     * This will get the building list and sends it as a request back to the view
     * @param c
     * @param force
     */
    public void setRequestBuildingList(Company c, Boolean force)
    {
        firePropertyChange(new RequestBuildingListChanged(getBuildings(c, force)));
    }


    public void setCurrentBuilding(Building b)
    {
        firePropertyChange(new BuildingDetailChanged(currentBuilding, b));
        currentBuilding = b;
    }
}
